<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>申请成为企业</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no,email=no" />
		<link rel="stylesheet" href="../css/mui.min.css">			
		<link rel="stylesheet" type="text/css" href="../css/mui.picker.min.css" />
		<link rel="stylesheet" href="../css/OA.css" />
		<link rel="stylesheet" type="text/css" href="../css/app.css" />
		<link href="../css/mui.picker.css" rel="stylesheet" />
		<link href="../css/mui.poppicker.css" rel="stylesheet" />
		<style>
			.mui-input-row>label{font-size:13px}		
			.mui-input-row #upPhoto{font-size:13px;color:#999;float: right;width: 65%;margin-bottom: 0;padding-left: 0;border: 0;height: 40px;line-height: 40px;}
            .showimg {
            	width:100%;
            	height:100px;
                margin: 10px 10px auto 10px;
                text-align: center;
            }	
		</style>
	</head>
	<body>
		<script src="../js/mui.min.js"></script>		
		<script src="../js/app.js"></script>
		<!--地区三级联动-->
		<script src="../js/mui.picker.min.js"></script>	
		<script src="../js/mui.poppicker.js"></script>
		<script src="../js/city.data-3.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/city.data.js" type="text/javascript" charset="utf-8"></script>
		<!--图片上传-->
		<script src="../js/photoCommon.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/image-new.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/binaryajax.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/exif.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/canvasResize.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" charset="utf-8">
			 //mui初始化
//			mui.init();
					
		</script>
		<header class="mui-bar mui-bar-nav">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title">申请成为企业</h1>
		</header>
		
		<div class="mui-content transparent">
			<div class="mui-card-header mui-card-media">
				<div class="showimg">

            	</div>
				
			</div>
			<div class="space-line"></div>
			<div class="mui-input-group" id="nomarlReg">
				<div class="mui-input-row ">
					<span class='mui-navigate-right'></span>
					<label>企业名称</label>
					<input id='companyName' type="text" class="mui-input-clear mui-input" placeholder="请输入企业名称">
				</div>
				<div class="mui-input-row ">
					<span class='mui-navigate-right'></span>
					<label>企业图片</label>
					<a id='upPhoto' href="#picture" type="text" class="mui-input-clear " placeholder="点击上传">点击上传图片</a>
				</div>
				<div class="mui-input-row ">
					<span class='mui-navigate-right'></span>
					<label>企业地址</label>
					<input id='' type="text" class="mui-input-clear " placeholder="请输入企业详细地址">
				</div>
				<div class="mui-input-row ">
					<span class='mui-navigate-right'></span>
					<label>所在省份</label>
					<input id='showCityPicker3' type="text" class="mui-input-clear " value=' '>
					
				</div>
				<div class="mui-input-row ">
					<span class='mui-navigate-right'></span>
					<label>企业电话</label>
					<input id='' type="number" class="mui-input-clear " placeholder="请输入企业电话">
				</div>
			</div>
			<div class="space-line"></div>
			<div class="mui-input-group" id="nomarlReg">
				<div class="mui-input-row">
					<span class='mui-navigate-right'></span>
					<label>联系人</label>  
					<input id='foundingTime' type="text" class="mui-input-clear " placeholder="请输入联系人">
				</div>
				<div class="mui-input-row">
					<span class='mui-navigate-right'></span>
					<label>联系电话</label>  
					<input id='foundingTime' type="number" class="mui-input-clear " placeholder="请选择开始时间">
				</div>		
			</div>
			<div class="space-line"></div>
			<div class="mui-input-group" id="nomarlReg">
				<div class="mui-input-row ">
					<span class='mui-navigate-right'></span>
					<label>营业执照号</label>
					<input id='BusinessLicenceNumber' type="number" class="mui-input-clear " placeholder="请输入营业执照号">
				</div>
				
				<div class="mui-input-row ">
					<span class='mui-navigate-right'></span>
					<label>注册资金</label>
					<input id='BusinessLicenceNumber' type="number" class="mui-input-clear " placeholder="请输入资金(必填)">
				</div>							
			</div>
			<div class="space-line"></div>
			<div class="mui-input-group" id="nomarlReg">
				<div class="mui-input-row">
					<span class='mui-navigate-right'></span>
					<label>联系人</label>  
					<input id='foundingTime' type="text" class="mui-input-clear " placeholder="请输入联系人">
				</div>
				<div class="mui-input-row">
					<span class='mui-navigate-right'></span>
					<label>联系电话</label>  
					<input id='foundingTime' type="number" class="mui-input-clear " placeholder="请选择开始时间">
				</div>		
			</div>
			<div class="submit"> 
				<button id="submit" type="button" class="mui-btn mui-btn-primary mui-btn-block">提交</button>
			</div>
		</div>
		<!--选择图片-->
	   <div id="picture" class="mui-popover mui-popover-action mui-popover-bottom">
				<ul class="mui-table-view">
					<li class="mui-table-view-cell">
						<a href="#" onclick="galleryImgs()">拍照</a>
					</li>
					<li class="mui-table-view-cell">
						<a href="#" onclick="cameraimages()">从相册选取</a>
					</li>
				</ul>
				<ul class="mui-table-view">
					<li class="mui-table-view-cell">
						<a href="#picture"><b>取消</b></a>
					</li>
				</ul>
		</div>
        
		<script>
			var showCityPicker3=document.getElementById('showCityPicker3');
			
		(function($, doc) {
				$.init();
				$.ready(function() {

					var cityPicker3 = new $.PopPicker({
						layer: 3
					});
					mui.plusReady(function() {
						mui.ajax('http://122.114.101.135/app/merchants/region?ReginId=-1',{
							dataType:'json',
							type:'get',
							timeout:10000,
							success:function(data){																		
								if(data.total="000"){
									console.log(cityData3);
									var cityData=data.Data
									console.log(cityData)
									cityPicker3.setData(cityData3);
								}else{
									plus.nativeUI.toast(data.info);
								}
							},
							error:function(xhr,type,errorThrown){
								plus.nativeUI.toast("提交失败,错误原因:"+errorThrown);
								   
							}
									   
										  
						}); 
					})
					document.getElementById('submit').addEventListener('tap',function(){
						mui.ajax('http://122.114.101.135/app/merchants/settled',{
							dataType:'json',
							type:'post',
							data:{
								CompanyName:'company',
								UserId:'549'
							},
							timeout:10000,
							success:function(data){																		
								if(data.total="000"){
									plus.nativeUI.toast('提交成功,等待审核')
									mui.back();
								}else{
									plus.nativeUI.toast(data.info);
								}
							},
							error:function(xhr,type,errorThrown){
								plus.nativeUI.toast("提交失败,错误原因:"+errorThrown);
								   
							}							   				  
						});
					})
					var showCityPickerButton = doc.getElementById('showCityPicker3');
					var cityResult3 = doc.getElementById('cityResult3');
					showCityPickerButton.addEventListener('tap', function(event) {
						cityPicker3.show(function(items) {
							showCityPicker3.value=(items[0] || {}).text + " " + (items[1] || {}).text + " " + (items[2] || {}).text
						})
					}, false);
				});
		})(mui, document); 
		 	//拍照
		 	
			function galleryImgs(){	
				
				
				mui('#picture').popover('toggle');
				getPics(true);
			}
			//从相册选
			function cameraimages(){
				
				mui('#picture').popover('toggle');
				getPics();
			}
           //上传单张图片
     	 	mui.plusReady(function() { 
				var o = imageTool.options;
				o.uploadUrl = 'http://demo.dcloud.net.cn/helloh5/uploader/upload.php'; //图片上传链接
				
				o.multiple = true; //默认只上传一张图片 ，如果要选择多张，请设置为true
				o.maxPicsCount = 6; //默认一次最多选择10张图片,
				o.ZoomBox = 1200; //缩放宽高，默认1200px,横图缩放宽度，高度根据比例计算，同理竖图
				o.ZoomQuality = 89; //压缩图片的质量
				o.isUpload = true; //默认不上传
				var mine = plus.webview.currentWebview();
				
				
			});
			function getPics(isCamera) {
				plus.nativeUI.showWaiting();
				//可以设置mask
				//main.setStyle({
				//	mask: '#ccc'
				//}); 
				
            	document.getElementsByClassName("showimg")[0].innerHTML = null;
				if (!isCamera) {
					imageTool.galleryImgs(doPics);
				} else {
					imageTool.camera(doPics);
				}
				
			}
			function doPics(err, list) {
				//因为dcloud官方上传地址上传后返回的格式并不是插件定义的规范，
				//"responseText":"{\"strings\":{\"uid\":\"39106184\",\"client\":\"HelloH5+\"},\"error\":\"0\",\"files\":{\"phillyx_72192431\":{\"name\":\"1464411747097.jpg\",\"url\":\"files\\/1464411747097.jpg\",\"type\":\"image\\/jpeg\",\"size\":245329}}}"
				//所以list内部数据都为空
				var err = '';
				var files = [];
				if (err) {
					console.log(err);
				}
				if (list) {
					mui.each(list, function(index, item) {
						console.log("err " + item.error);
						if (item.imgUrl) {
							files.push(item.imgUrl);
						}
					});
				}
				console.log('上传图片地址：' + JSON.stringify(files));
				//关掉mask
				//main.setStyle({
				//	mask: 'none'
				//});
				showImg(files)
				if (files.length > 0) {
					//在这里做项目的逻辑，可以打开新页面将files传过去
				}
			};
			function showImg(url) {
		    // 兼容以“file:”开头的情况
		    if (0 != url.toString().indexOf("file://")) {
		        url = "file://" + url;
		    }
		    var _div_ = document.getElementsByClassName("showimg")[0];
		    var _img_ = new Image();
		    _img_.src = url; // 传过来的图片路径在这里用。
		        _img_.onclick = function() {
		                plus.runtime.openFile(url);
		            };
		    _img_.onload = function() {
		        var tmph = _img_.height;
		        var tmpw = _img_.width;
		        var isHengTu = tmpw > tmph;
		        var max = Math.max(tmpw, tmph);
		        var min = Math.min(tmpw, tmph);
		        var bili = min / max;
		        if (max > 1200) {
		            max = 1200;
		            min = Math.floor(bili * max);
		        }
		        tmph = isHengTu ? min : max;
		        tmpw = isHengTu ? max : min;
		        _img_.style.border = "1px solid rgb(200,199,204)";
		        _img_.style.margin = "10px";
		        _img_.style.width = "80px";
		        _img_.style.height = "80px";
		        _img_.onload = null;
		        _img_.src = url;
		        _div_.appendChild(_img_);
//		        plus.io.resolveLocalFileSystemURL(url, function(entry) {
//		                entry.file(function(file) {
//		                    console.log(file.size + '--' + file.name);
//		                    canvasResize(file, {
//		                        width: tmpw,
//		                        height: tmph,
//		                        crop: false,
//		                        quality: 50, //压缩质量
//		                        rotate: 0,
//		                        callback: function(data, width, height) {
//		                            f1.push(data);
//		                            
//		                            plus.nativeUI.closeWaiting();
//		                        }
//		                    });
//		                });
//		            },
//		            function(e) {
//		                plus.nativeUI.closeWaiting();
//		                console.log(e.message);
//		            });
		    };
		};
		</script>
	</body>
</html>
